package org.usyk.util;

import org.usyk.combinatorics.PositionalNotationUtil;

/**
 * Created by IntelliJ IDEA.
 * User: Алексейка
 * Date: 19.02.12
 * Time: 13:39
 * To change this template use File | Settings | File Templates.
 */
public class NumbersFilter {

    /**
     * The logic is to find all different characters at string
     * and then check whether them are located at the right place
     * 'right' means: 0 is loacated at 0 place and so on.
     * <BR/>Example:
     * <BR/>00224 - OK
     * <BR/>01333 - OK
     * <BR/>10324 - NOT OK
     *
     * @param numberInNumericalSystem
     * @return
     */
    public static boolean isWellFormed(String numberInNumericalSystem) {
        int systemBase = numberInNumericalSystem.length();
        char[] array = numberInNumericalSystem.toCharArray();

        for (int i = 0; i < systemBase; i++) {
            char c = array[i];
            int indexToFind = Integer.parseInt(Character.toString(c));
            if (Integer.parseInt(Character.toString(array[indexToFind])) != indexToFind) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {

        //        System.out.println("10324 = " + isWellFormed("10324"));
        //        System.out.println("01333 = " + isWellFormed("01333"));
        //        System.out.println("00224 = " + isWellFormed("00224"));


        for (int i = 0; i < 3 * 3 * 3; i++) {
            String num = PositionalNotationUtil.numberInNumSystem(i,3);
            System.out.println(num + " = " + isWellFormed(num));
        }
    }

}

